import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
	{
		path: '/',
		name: 'Main',
		component: () => import('../views/Main.vue')
	},
	{
		path: '/register',
		name: 'Register',
		component: () => import('../views/Register.vue')
	},
	{
		path: '/authorReg',
		name: 'AuthorRegister',
		component: () => import('../views/AuthorRegister.vue')
	},
	{
		path: '/novel/:id',
		name: 'Novel',
		component: () => import('../views/Novel.vue')
	},
	{
		path: '/read/:bookId/:chapterId',
		name: 'Read',
		component: () => import('../views/Read')
	},
	{
		path: '/category/:id',
		name: 'Category',
		component: () => import('../views/Category')
	},
	{
		path: '/seach/*',
		name: 'seach',
		component: () => import('../views/Seach')
	},
	{
		path: "/user",
		name: "user",
		component: function() {
			return import("../views/User.vue")
		},
		children: [{
				path: "charge",
				name: "charge",
				component: function() {
					return import("../components/user/Charge.vue")
				},
			},
			{
				path: "coll",
				name: "coll",
				component: function() {
					return import("../components/user/Coll.vue")
				},
			},
			{
				path: "info",
				name: "info",
				component: function() {
					return import("../components/user/Info.vue")
				},
			},
		]
	},
	{
		path: "/author",
		name: "author",
		component: function() {
			return import("../views/Author.vue")
		},
		beforeEnter: (to, from, next) => {
			if (!sessionStorage.getItem("authorId")) {
				next({
					path: '/register'
				})
			} else {
				next()
			}
		},
		children: [{
				path: "index",
				name: "index",
				component: function() {
					return import("../components/author/Index.vue")
				},
			},
			{
				path: "novellist",
				name: "novellist",
				component: function() {
					return import("../components/author/Novellist.vue")
				},
			},
			{
				path: "welfare",
				name: "welfare",
				component: function() {
					return import("../components/author/Welfare.vue")
				},
			},
			{
				path: "novelinfo",
				name: "novelinfo",
				component: function() {
					return import("../components/author/NovelInfo.vue")
				},
			},
			{
				path: "signApply",
				name: "signApply",
				component: function() {
					return import("../components/author/SignApply.vue")
				},
			},
			{
				path: "agreement",
				name: "agreement",
				component: function() {
					return import("../components/author/Agreement.vue")
				},
			},
		]
	}
]


const router = new VueRouter({
	mode: 'history',
	routes
})

export default router
